<%--
Copyright 2011 Michele Mancioppi [michele.mancioppi@gmail.com]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--%>
<%@ page language="java" contentType="application/xhtml+xml; charset=UTF-8" pageEncoding="UTF-8" %>
<%
String emailAddress = request.getParameter("emailAddress");
if (emailAddress == null) {
	throw new JspException(
	"The required parameter 'emailAddress' was not provided");
}

String challenge = request.getParameter("challenge");
if (challenge == null) {
	throw new JspException(
	"The required parameter 'challenge' was not provided");
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() { 
	$.ajax({
		url:			"/resources/accounts/<%= emailAddress %>/tests/answer",
		type:			"put",
		data: {
			challenge: "<%= challenge %>"
		},
		success:		showSuccess,
		error:			showError
	});
});
function showSuccess(data, textStatus, jqXHR) {
	$('#outcome').html('The test has been successfully answered');	
}
function showError(jqXHR, textStatus, errorThrown) {
	$('#outcome').html('An error has occurred while processing the request: ' + textStatus + ' (' + errorThrown + ')');
}
</script>
<title>Answer a TestMessage test</title>
</head>
<body>
<h1>Answering the test with challenge <%= challenge %> for the email address <%= emailAddress %></h1>
<div id="outcome">
<p>Hang on while the test is verified.</p>
</div>
</body>
</html>